﻿using Ruddish.UI.Froms;
using Ruddish.UI.UserControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ruddish.UI
{
    public partial class FrmMianMuen : Form
    {
        #region 页面收缩参数
        int PanelWindth;
        bool isCollapsed;
        #endregion

        #region 使窗体可以移动的代码_1

        [DllImport("user32.dll")]

        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]

        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);

        public const int WM_SYSCOMMAND = 0x0112;

        public const int SC_MOVE = 0xF010;

        public const int HTCAPTION = 0x0002;

        #endregion
        #region 使窗体可以移动的代码_2
        private void uiPanel1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();

            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);

            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        #endregion

        public FrmMianMuen()
        {
            InitializeComponent();
            timerTime.Start(); //时间显示
            #region 页面收缩参数赋值
            PanelWindth = panelLeft.Width;
            isCollapsed = false;
            #endregion

            // 内框转换
            UC_HomePage uC_HomePage = new UC_HomePage();
            AddControlsTopPanel(uC_HomePage);
        }

        /// <summary>
        /// 关闭程序控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        /// <summary>
        /// 收缩控件的条件代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (isCollapsed)
            {
                panelLeft.Width = panelLeft.Width + 10;
                if (panelLeft.Width>=PanelWindth)
                {
                    timer1.Stop();
                    isCollapsed = false;
                    this.Refresh();
                }
            }
            else
            {
                panelLeft.Width = panelLeft.Width - 10;
                if (panelLeft.Width <= 85)
                {
                    timer1.Stop();
                    isCollapsed = true;
                    this.Refresh();
                }
            }
        }

        /// <summary>
        /// 收缩控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnShrink_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        /// <summary>
        /// 选择框控件左侧的白块跟随
        /// </summary>
        /// <param name="btn"></param>
        private void moveSidePanel(Control btn)
        {
            panelSide.Top = btn.Top;
            panelSide.Height = btn.Height;
        }

        /// <summary>
        /// 投放点控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddress_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnAddress);

            //内框转换
            UC_Address uC_Address = new UC_Address();
            AddControlsTopPanel(uC_Address);
        }

        /// <summary>
        /// 积分控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPoint_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnPoint);

            //内框转换
            UC_Point uC_Point = new UC_Point();
            AddControlsTopPanel(uC_Point);
        }

        /// <summary>
        /// 商城控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnShopp_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnShopp);

            //内框转换
            UC_Shopp uC_Shopp = new UC_Shopp();
            AddControlsTopPanel(uC_Shopp);
        }

        /// <summary>
        /// 回收控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRecycle_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnRecycle);

            //内框转换
            UC_Recycle uC_Recycle = new UC_Recycle();
            AddControlsTopPanel(uC_Recycle);
        }

        /// <summary>
        /// 课堂控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStudy_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnStudy);

            //内框转换
            UC_Study uC_Study = new UC_Study();
            AddControlsTopPanel(uC_Study);
        }

        /// <summary>
        /// 设置控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetup_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnSetup);

            // 内框转换
            UC_Setup uC_Setup = new UC_Setup();
            AddControlsTopPanel(uC_Setup);
        }

        /// <summary>
        /// 首页控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHomePage_Click(object sender, EventArgs e)
        {
            //白块跟随
            moveSidePanel(btnHomePage);

            // 内框转换
            UC_HomePage uC_HomePage = new UC_HomePage();
            AddControlsTopPanel(uC_HomePage);
        }

        /// <summary>
        /// 智能时钟
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerTime_Tick(object sender, EventArgs e)
        {
            DateTime dt =DateTime.Now;
            txtTime.Text = dt.ToString("HH:mm:ss");
        }

        /// <summary>
        /// 内框变换
        /// </summary>
        /// <param name="c"></param>
        private void AddControlsTopPanel(Control c)
        {
            c.Dock = DockStyle.Fill;
            panelControls.Controls.Clear();
            panelControls.Controls.Add(c);
        }

        private void LabelLogIn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmLogIn frmLogIn = new FrmLogIn();
            frmLogIn.Show();
        }

        private void btnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            this.btnMin.Visible = true;
        }
    }
}
